package com.sfpay.coreplatform.order.service.validate;

import com.sfpay.coreplatform.order.common.OrderResponseCode;
import com.sfpay.coreplatform.order.service.exception.OrderServiceException;
import com.sfpay.framework.base.utils.StringUtils;

public class ValidateUtil {
	
	/**
	 * yyyyMMdd日期格式
	 */
	private static final String DATE_FORMAT1_REGEX = "^\\d{8}$";  
	
	/**
	 * 方法说明:验证字符串是否为空
	 * @param source
	 * @param errMsg
	 * @throws OrderServiceException
	 */
	public static void validateEmpty(String source, String errMsg) throws OrderServiceException {
		if(StringUtils.isEmpty(source)){
				throw new OrderServiceException(
						OrderResponseCode.ORDER_RESPONSE_PARAM_ISNULL,
						errMsg);
		}
				
	}
	
	/**
	 * 方法说明:验证传入日期是否正确,日期格式为yyyyMMdd
	 * @param source
	 * @param errMsg
	 * @throws OrderServiceException
	 */
	public static void validateDateFormat1(String source, String errMsg) throws OrderServiceException{
		
		if(source == null || !source.matches(DATE_FORMAT1_REGEX)){
			throw new OrderServiceException(
					OrderResponseCode.ORDER_COMMON_PARAM_ERR_FORMAT,
					errMsg);
		}
		
	}
	
	public static void validateNull(Object source, String errMsg ) throws OrderServiceException{
		
		if(source == null){
			throw new OrderServiceException(
					OrderResponseCode.ORDER_RESPONSE_PARAM_ISNULL,
					errMsg);
		}
	}
	
}

